<?php
namespace Home\Controller;

class ArticleController extends PublicController
{
    public function add()
    {
        $cate = M('category');
        $cates=$cate->select();
        $this->assign("cates",$cates);
//        p($cates);
//        exit();
        $this->display();
    }
    

    public function insert()
    {
        $re=$this->upload('aimg');
        if (!$re[0]){
            $this->error($re[1]);
            exit;
        }else{
            $iname=$re[1];
        }
        $_POST['uid']= 1;
        $_POST['keywords']= "随笔";
        $_POST['description']= "随笔";
        $_POST['is_show']= 1;
        $_POST['is_delete']= 0;
        $_POST['is_top']= 0;
        $_POST['is_original']= 1;
        $_POST['click']= 0;
        $_POST['ds']= 0;
        $_POST['time']= time();
        $artcle=M('article');
        if (!$artcle->create()) {
            //如果创建失败  表示验证没有通过 输出错误提示信息
            $this->error($artcle->getError());
        } else {
            //验证通过
            $aid=M('article')->add();
            if ($aid > 0) {
                $a_pic = array();
                $a_pic['iname']=$iname;
                $a_pic['aid']=$aid;
                if (M('article_pic')->add($a_pic))
                $this->success('添加成功',U('Home/Index/index'));
            } else {
                $this->error('添加失败');
            }
        }
    }
}